package com.meng.file.filter;

import com.meng.file.session.CurrentSession;
import org.springframework.core.annotation.Order;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@WebFilter(filterName = "authFilter", urlPatterns = "/*")
@Order(1)
public class SessionFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        String requestId = req.getHeader("requestId");
        CurrentSession.setRequestId(requestId);
        filterChain.doFilter(servletRequest, servletResponse);
        System.out.println(requestId);
//        CurrentSession.setRequestId(null);
    }

    @Override
    public void destroy() {
        System.out.println("destroy");
    }
}
